<?php 
class functions{
	function format_size($size) {
       $sizes = array(" Bytes", " KB", " MB", " GB", " TB", " PB", " EB", " ZB", " YB");
       if ($size == 0) { return('n/a'); } else {
       return (round($size/pow(1024, ($i = floor(log($size, 1024)))), 2) . $sizes[$i]); }
 	}
 	function checkLink($link){
		 flush();
		 $fp = @fopen($link, "r");
		 @fclose($fp);
		 if (!$fp){ return false;}else{ return true;}
		 //คำสั่งเรียกใช้ if ($result = checkLink("http://planet.kapook.com/​files/photo/2/​23185_1624937396.jpg")){echo "Link works";} else {echo"Link doesn't work;";}
		 // Checks URL for a working page. Returns true if link is valid.
	}
	function random_password($len){
		srand((double)microtime()*10000000);
		$chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
		$ret_str = "";
		$num = strlen($chars);
		for($i = 0; $i < $len; $i++){
			$ret_str.= $chars[rand()%$num];
			$ret_str.=""; 
		}
		return $ret_str; 
	}
	function getIP(){  
	    // ตรวจสอบ IP กรณีการใช้งาน share internet  
	    if(!empty($_SERVER['HTTP_CLIENT_IP'])){  
	      $ip=$_SERVER['HTTP_CLIENT_IP'];  
	    }else{  
	      $ip=$_SERVER['REMOTE_ADDR'];  
	    }  
	    return $ip;  
	}  

}
?>
